<?php
require_once('mysql_table.php');

class edificio extends mysql_table{

    function __construct(){
        parent::__construct();
        $this->TableName = "EDIFICIOS";
        $this->IDField = "ID";        
        
        $this->fields['ID']  = "";
        $this->fields['NOMBRE']  = "";
        $this->fields['DIRECCION']  = "";
        $this->fields['TELEFONO']  = "";
        $this->fields['MAIL']  = "";
        $this->fields['ID_EMPRESA']  = "";
        $this->fields['COSTO_ENVIO'] = "";
        $this->fields['LUNES']  = "";
        $this->fields['MARTES']  = "";
        $this->fields['MIERCOLES']  = "";
        $this->fields['JUEVES']  = "";
        $this->fields['VIERNES']  = "";
        $this->fields['SABADO']  = "";
        $this->fields['DOMINGO']  = "";
        $this->fields['ID_STATUS']  = "";
        
    }
    
    /**
     *@return los edificios de todas las empresas
     *@example para listarlos
     **/
    function buscar(){
        
        $query = "SELECT EDIFICIOS.*, EMPRESAS.NOMBRE AS EMPRESA FROM EDIFICIOS, EMPRESAS
                    WHERE EDIFICIOS.ID_STATUS != 0 AND
                    EDIFICIOS.ID_EMPRESA = EMPRESAS.ID AND 
                    EMPRESAS.ID_STATUS !=0 ORDER BY EMPRESA";
        $salida = $this->tovector_assoc_query($query);
        //print($query);
        return $salida;
            
    }
    
    function buscar_uno($id_empresa){
        
        $query = "SELECT * FROM EDIFICIOS WHERE ID_STATUS != 0 AND ID_EMPRESA =".$id_empresa;
        $salida = $this->tovector_assoc_query($query);
        //print($query);
        return $salida;
            
    }
    
    function buscar_direccion_cliente($id_cliente){
        
       $query = "select e.* from EDIFICIOS e, CLIENTES c where e.ID = c.ID_EDIFICIO and c.ID = ".$id_cliente;
        $result = $this->runquery($query);
        //print_r($query);
        if ($this->SQLObject->num_rows($result) == 0) {
            return false;
        } else {
            $this->getdata($result);
            return true;
        }
            
    }
    
    function unique($Column,$Value,$id_empresa){
        $query = "SELECT * FROM " . $this->TableName ." WHERE ".$Column."=" . $Value." AND ID_EMPRESA=".$id_empresa." AND ID_STATUS=1";
        $result = $this->runquery($query);
        //print_r($query);
        if ($this->SQLObject->num_rows($result) == 0) {
            return false;
        } else {
            $this->getdata($result);
            return true;
        }
    }
}
?>
